/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * evaluationInterface.java
 *
 * Created on 2011年4月14日, 上午02:36:45
 */

package csci3170;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;

/**
 *
 * @author KOLee
 */
public class evaluationInterface extends javax.swing.JFrame {

    /** Creates new form evaluationInterface */
    public evaluationInterface() {
        initComponents();


        //Show All Information (SAI)
        SAI_bShow.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e) {
               courseEnrollmentSystem s = courseEnrollmentSystem.getApplication();

               String[] query = {"Course","SELECT * FROM Course","TermCourse","SELECT * FROM TermCourse","Student","SELECT * FROM Student",
                                 "Enrollment","SELECT * FROM Enrollment","Prerequisite","SELECT * FROM Prerequisite"};
               s.setInput(query);

              
                  Result result =  s.getOutput();

                if(result.Check.equals( "false" ) ){
                    JOptionPane.showMessageDialog(null, "Fail!");
               }else{
                      String tables ="";
                      for(String table:result.Set){
                        tables += table+"\n\n";
                        System.out.println( " result: \n" +table);
                    }

                      SAI_DisplayArea.setText(tables+"\n");

               }
        //       System.out.println(result);

            };



        });



        //Show Popular coures
        SPC_bShow.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e) {

               String number;

               number = SPC_tNumber.getText();
            
            
                   courseEnrollmentSystem s = courseEnrollmentSystem.getApplication();
//"CourseID CourseName                                         Year Term Credit Department Professor     Quota NumberOfEnrolledStudent "
//"CourseID Philosophy and Contemporary Problems               2010 2 2 GEU Pear                                               15 15 "

                   String[] query = {"PopularCourse", "SELECT * "
                                            +" FROM ( "
                                            +" SELECT C.CourseID, C.CourseName, TC.Year, TC.Term, C.Credit, C.Department, TC.Professor, TC.Quota, TC.NumberOfEnrolledStudent"
                                            +" FROM Course C, TermCourse TC"
                                            +" WHERE C.CourseID = TC.CourseID"
                                            +" ORDER BY TC.NumberOfEnrolledStudent DESC"
                                            +" )"
                                            +" WHERE rownum <= "+number+""
                                     };




                   s.setInput(query);


                      Result result =  s.getOutput();

                    if(result.Check.equals( "false" ) ){
                        JOptionPane.showMessageDialog(null, "Fail!");
                   }else{
                          String tables ="";
                          for(String table:result.Set){
                            tables += table+"\n\n";
                            System.out.println( " result: \n" +table);
                        }

                           StringBuilder  a = new StringBuilder(tables);


                          SPC_DisplayArea.setText(tables+"\n");

                   }
               

            }



        });




        //Show Student Information
        SSI_bShow.addActionListener(new ActionListener(){

             public void actionPerformed(ActionEvent e) {

               String Term,NCredit,Year;
               Term = SSI_tTerm.getText();
               NCredit = SSI_tCredits.getText();
               Year = SSI_tYear.getText();

              
                   courseEnrollmentSystem s = courseEnrollmentSystem.getApplication();
                //"CourseID CourseName                                         Year Term Credit Department Professor     Quota NumberOfEnrolledStudent "
                //"CourseID Philosophy and Contemporary Problems               2010 2 2 GEU Pear                                               15 15 "

                     String[] query = { "StudentInformaiton", " SELECT R.StudentID, S2.Name, R.TotalCredit, S2.Gender, S2.Address, S2.Major, S2.College, S2.DateOfBirth, S2.Phone, S2.AdmissionYear"  //May display more information about the student
                                            +" FROM ("
                                            +" SELECT S.StudentID, SUM(C.Credit) AS TotalCredit "
                                            +" FROM Student S, Enrollment E, Course C "
                                            +" WHERE S.StudentID = E.StudentID AND E.CourseID = C.CourseID AND E.Year = "+Year+" AND E.Term = "+Term+" "
                                            +" GROUP BY S.StudentID "
                                            +" ) R, Student S2 "
                                            +" WHERE R.StudentID = S2.StudentID AND R.TotalCredit > "+NCredit+" "
                                            +" ORDER BY R.TotalCredit DESC "
                                     };





                   s.setInput(query);


                      Result result =  s.getOutput();

                    if(result.Check.equals( "false" ) ){
                        JOptionPane.showMessageDialog(null, "Fail!");
                   }else{
                          String tables ="";
                          for(String table:result.Set){
                            tables += table+"\n\n";
                            System.out.println( " result: \n" +table);
                        }

                          SSI_DisplayArea.setText(tables+"\n");

                   }
                

            }



        });





    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        evalInterface = new javax.swing.JTabbedPane();
        SAI = new javax.swing.JPanel();
        SAI_bShow = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        SAI_DisplayArea = new javax.swing.JTextArea();
        SPC = new javax.swing.JPanel();
        SPC_tNumber = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        SPC_bShow = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        SPC_DisplayArea = new javax.swing.JTextArea();
        SSI = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        SSI_DisplayArea = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        SSI_tYear = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        SSI_tTerm = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        SSI_tCredits = new javax.swing.JTextField();
        SSI_bShow = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        evalInterface.setName("evalInterface"); // NOI18N

        SAI.setName("SAI"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(csci3170.courseEnrollmentSystem.class).getContext().getResourceMap(evaluationInterface.class);
        SAI_bShow.setText(resourceMap.getString("SAI_bShow.text")); // NOI18N
        SAI_bShow.setName("SAI_bShow"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        SAI_DisplayArea.setColumns(20);
        SAI_DisplayArea.setEditable(false);
        SAI_DisplayArea.setRows(5);
        SAI_DisplayArea.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        SAI_DisplayArea.setName("SAI_DisplayArea"); // NOI18N
        jScrollPane1.setViewportView(SAI_DisplayArea);

        javax.swing.GroupLayout SAILayout = new javax.swing.GroupLayout(SAI);
        SAI.setLayout(SAILayout);
        SAILayout.setHorizontalGroup(
            SAILayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SAILayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(SAILayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
                    .addComponent(SAI_bShow, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        SAILayout.setVerticalGroup(
            SAILayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SAILayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(SAI_bShow, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                .addContainerGap())
        );

        evalInterface.addTab(resourceMap.getString("SAI.TabConstraints.tabTitle"), SAI); // NOI18N

        SPC.setName("SPC"); // NOI18N

        SPC_tNumber.setColumns(5);
        SPC_tNumber.setText(resourceMap.getString("SPC_tNumber.text")); // NOI18N
        SPC_tNumber.setName("SPC_tNumber"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        SPC_bShow.setText(resourceMap.getString("SPC_bShow.text")); // NOI18N
        SPC_bShow.setName("SPC_bShow"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        SPC_DisplayArea.setColumns(20);
        SPC_DisplayArea.setEditable(false);
        SPC_DisplayArea.setRows(5);
        SPC_DisplayArea.setName("SPC_DisplayArea"); // NOI18N
        jScrollPane2.setViewportView(SPC_DisplayArea);

        javax.swing.GroupLayout SPCLayout = new javax.swing.GroupLayout(SPC);
        SPC.setLayout(SPCLayout);
        SPCLayout.setHorizontalGroup(
            SPCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SPCLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(SPCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(SPCLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(SPC_tNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 295, Short.MAX_VALUE)
                        .addComponent(SPC_bShow))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE))
                .addContainerGap())
        );
        SPCLayout.setVerticalGroup(
            SPCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SPCLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(SPCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(SPC_tNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SPC_bShow))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
                .addContainerGap())
        );

        evalInterface.addTab(resourceMap.getString("SPC.TabConstraints.tabTitle"), SPC); // NOI18N

        SSI.setName("SSI"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        SSI_DisplayArea.setColumns(20);
        SSI_DisplayArea.setEditable(false);
        SSI_DisplayArea.setRows(5);
        SSI_DisplayArea.setName("SSI_DisplayArea"); // NOI18N
        jScrollPane3.setViewportView(SSI_DisplayArea);

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        SSI_tYear.setColumns(5);
        SSI_tYear.setText(resourceMap.getString("SSI_tYear.text")); // NOI18N
        SSI_tYear.setName("SSI_tYear"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        SSI_tTerm.setColumns(5);
        SSI_tTerm.setText(resourceMap.getString("SSI_tTerm.text")); // NOI18N
        SSI_tTerm.setName("SSI_tTerm"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        SSI_tCredits.setColumns(5);
        SSI_tCredits.setText(resourceMap.getString("SSI_tCredits.text")); // NOI18N
        SSI_tCredits.setName("SSI_tCredits"); // NOI18N

        SSI_bShow.setText(resourceMap.getString("SSI_bShow.text")); // NOI18N
        SSI_bShow.setName("SSI_bShow"); // NOI18N

        javax.swing.GroupLayout SSILayout = new javax.swing.GroupLayout(SSI);
        SSI.setLayout(SSILayout);
        SSILayout.setHorizontalGroup(
            SSILayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, SSILayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(SSILayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
                    .addGroup(SSILayout.createSequentialGroup()
                        .addGroup(SSILayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(SSI_tYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(SSILayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(SSI_tTerm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(SSILayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(SSI_tCredits, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(228, 228, 228)
                        .addComponent(SSI_bShow)))
                .addContainerGap())
        );
        SSILayout.setVerticalGroup(
            SSILayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SSILayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(SSILayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(SSILayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SSI_tYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SSI_tTerm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SSI_bShow)
                    .addComponent(SSI_tCredits, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
                .addContainerGap())
        );

        evalInterface.addTab(resourceMap.getString("SSI.TabConstraints.tabTitle"), SSI); // NOI18N

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(csci3170.courseEnrollmentSystem.class).getContext().getActionMap(evaluationInterface.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(evalInterface, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(evalInterface, javax.swing.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
  /*  public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new evaluationInterface().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel SAI;
    private javax.swing.JTextArea SAI_DisplayArea;
    private javax.swing.JButton SAI_bShow;
    private javax.swing.JPanel SPC;
    private javax.swing.JTextArea SPC_DisplayArea;
    private javax.swing.JButton SPC_bShow;
    private javax.swing.JTextField SPC_tNumber;
    private javax.swing.JPanel SSI;
    private javax.swing.JTextArea SSI_DisplayArea;
    private javax.swing.JButton SSI_bShow;
    private javax.swing.JTextField SSI_tCredits;
    private javax.swing.JTextField SSI_tTerm;
    private javax.swing.JTextField SSI_tYear;
    private javax.swing.JTabbedPane evalInterface;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JMenuBar menuBar;
    // End of variables declaration//GEN-END:variables

}
